package me.yricky.mayu.ui.fasta_list

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import me.yricky.mayu.ui.ItemCard
import me.yricky.mayu.ui.LazyColumnWithScrollBar
import me.yricky.mayu.ui.fasta.DataContentItem
import me.yricky.mayu.ui.fasta.FastaSeqModel

/**
 * @author Yricky
 * @date 2022/4/24
 */

@Composable
fun FastaListModel.VerticalList(modifier: Modifier = Modifier, autoLoadMore:Boolean = true, onClick:(FastaSeqModel)->Unit = {}) {
    LazyColumnWithScrollBar(
        modifier.fillMaxSize(),
    ) {
        items(fastaList){
            ItemCard{
                it.DataContentItem(
                    Modifier
                    .fillMaxWidth()
                    .clickable { onClick(it) }
                    .padding(8.dp)
                )
            }
            if(fastaList.lastOrNull() == it && autoLoadMore){
                loadMore()
            }
        }
    }
}

@Composable
fun FastaListModel.CountBadge(modifier: Modifier = Modifier){
    Surface(
        modifier = modifier,
        shape = RoundedCornerShape(64.dp),
        color = MaterialTheme.colors.secondary,
        elevation = 8.dp
    ) {
        Box(
            Modifier
                .clickable { loadMore() }
                .padding(4.dp),
        ){
            Text(
                "${fastaList.size}${if(hasMore)"+" else ""}",
                color = MaterialTheme.colors.onSecondary
            )
        }
    }
}